//
//  CustomMadeCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/9.
//  Copyright © 2018年 Lwx. All rights reserved.
//
#import "CustomMadeCell.h"

@interface CustomMadeCell()
@property(nonatomic, strong)UILabel * titleLab;
@property(nonatomic, strong)UILabel * contentLab;
@property(nonatomic, strong)UIButton * orderBtn;
@property(nonatomic, assign)NSString * customMadeID;//私人订制ID
@property (nonatomic, strong)NSString * orderPayStr;//预定金
@property (nonatomic, strong)NSString * tid;//旅游Id
@end

@implementation CustomMadeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.contentView.backgroundColor = [UIColor greenColor];
        self.selectionStyle =UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.orderBtn];
    }return self;
}

- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.text = @"XXXXXXXXXXXX";
        _titleLab.font = DEF_FontSize_12;
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.textColor = [UIColor blackColor];
//        _titleLab.backgroundColor = [UIColor yellowColor];
    }return _titleLab;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.text = @"XXXXXXXXXXXX";
        _contentLab.font = DEF_FontSize_12;
        _contentLab.textAlignment = NSTextAlignmentLeft;
        _contentLab.textColor = [UIColor redColor];
//        _contentLab.backgroundColor = [UIColor grayColor];
    }return _contentLab;
}

- (UIButton *)orderBtn{
    if (!_orderBtn) {
        _orderBtn = [[UIButton alloc] init];
        [_orderBtn setTitle:@"预定" forState:UIControlStateNormal];
        [_orderBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_orderBtn setBackgroundColor:[UIColor orangeColor]];
        [_orderBtn setCornerRadius:6];
        _orderBtn.titleLabel.font = DEF_FontSize_14;
        [_orderBtn addTarget:self action:@selector(orderBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _orderBtn;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat border = 10;
    CGFloat orderBtnW = 40;
    CGFloat orderBtnY = 20;
    CGFloat labelH = 20;
    CGFloat labelY = (self.contentView.height - 2*labelH)/2;
    self.orderBtn.frame = CGRectMake(SCREEN_WIDTH - border - orderBtnW, 0, orderBtnW, orderBtnY );
    self.orderBtn.centerY = self.contentView.centerY;
    self.titleLab.frame = CGRectMake(border, labelY, self.orderBtn.left - border - border, labelH);
    self.contentLab.frame = CGRectMake(self.titleLab.left, self.titleLab.bottom, self.titleLab.width, self.titleLab.height);
}

- (void)setCustomModelData:(CustomMadeModelData *)customModelData{
    _customModelData = customModelData;
    self.titleLab.text = customModelData.title;
    self.customMadeID = customModelData.customMadeID;
    self.contentLab.text = [NSString stringWithFormat:@"%@元", customModelData.price];
    self.orderPayStr = customModelData.price;
    self.tid = customModelData.tid;
}

- (void)orderBtnClick{
    NSLog(@"预定按钮");
    if (self.reservePay) {
        self.reservePay(self.customMadeID, self.orderPayStr, self.tid);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
